﻿@{
	ViewBag.Title = "Examples";
}

<h2>Examples</h2>
<div>
	Here are some code samples to get you started
</div>

<h3>Creating the Container</h3>
<div>
	Just create a new instance of the Container object.
	<code>
		var container = new IocContainer();
	</code>
			
	It is possible to change the default lifetime used when registering (the default lifetime is Transient which always create a new instance).
	<code>
		var container = new IocContainer(() => new ContainerLifetime());
	</code>
</div>



Mention defining what constructor to use?
Compile Mode

Scope resolving
Lambda Registration
Request / Session lifetime

lazyresolve / getfactory ... 


Update feature list



<h3>Registration</h3>
<div>
	Registering your type / implementations is very easy.
	<br />
	The easiest way to register a type is using the Register method that takes 2 generic parameters.
	<br />
	It will automatically use the constructor of the implementation type that takes the most parameters.
	<code>
		container.Register&lt;IFoo, Foo&gt;();
	</code>

	If you want full control of how the type being registered is initialized you can use a lambda expression
	<code>
		container.Register&lt;IFoo&gt;(c =&gt; new Foo(c.Resolve&lt;IBar&gt;()));
	</code>

	You can do property injection like this
	<code>
		container.Register&lt;IFoo&gt;(c =&gt; new Foo() { Bar = c.Resolve&lt;IBar&gt;() });
	</code>

	It is also possible to register an instance by using the RegisterInstance method
	<code>
		container.RegisterInstance&lt;IFoo&gt;(theInstance);
	</code>

	It is possible to Compile the registrations to make them resolve faster.
	<br />
	Please be aware that changing the lifetime of a registration that is used in a Compiled registration will not be reflected.
	<code>
		container.Compile();
	</code>
</div>

<h3>Resolving</h3>
<div>
	Resolving registrations is straight forward.
	<br />

	To resolve a single instance of a specific type use the Resolve / TryResolve methods.
	<code>
		var instance = container.Resolve&lt;IFoo&gt;();
	</code>

	It is also possible to Resolve all registrations for a specific type using the ResolveAll / TryResolveAll methods.
	<code>
		var instances = container.ResolveAll&lt;IFoo&gt;();
	</code>
</div>

<h3>Lifetime</h3>
<div>
	<div>
		Dynamo comes with build-in support for Transient (new instance), Container (singleton), Request, Session, Cache, ThreadLocal -Lifetime.
	</div>
	
	<br />

	You can use the WithLifetime method to set the lifetime for a specific registration
	<code>
		container.Register&lt;IFoo, Foo&gt;().WithLifetime(Lifetime.Container());
	</code>

	For Web scenarios Dynamo supports creating a new instance for each request and automatically calling Dispose on the object at the EndRequest event if it implements the IDisposable interface.
	This feature currently relies on System.Web.Webpages. It is included when installing Microsoft Asp.Net WebPages which comes with MVC 3 etc.
	<code>
		container.Register&lt;IFoo, Foo&gt;().WithLifetime(Lifetime.Request().DisposeOnEnd());
	</code>
</div>

<h3>Custom Lifetime</h3>
<div>
	Dynamo uses a pluggable lifetime system that makes it easy to create and use your own custom lifetime.
	<br />
	You can implement your own custom lifetime by implementing the ILifetime interface or the abstract LifetimeBase class.
	<br />
	If you want to add your custom lifetime implementation to the Lifetime interface you can create an extension method extending the LifetimeExtension class.
</div>

<h3>Registering Dependency Resolver</h3>
<div>
	You will find the DependencyResolver under the Dynamo.Ioc.Web namespace.
	<br />
	Register it in the Application_Start() method in the Global.asax or inherit from the DynamoHttpApplication.
	<br />
	<code>
		var container = new Container();
		<br />
		var resolver = new DynamoDependencyResolver(container);
		<br />
		RegisterDependencyResolver(resolver);
	</code>
</div>